<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML>
<head>
	<title>Address</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link href="/css/home/style.css" rel="stylesheet" type="text/css" media="all"/>
	<script type="text/javascript" src="/js/common/jquery-3.1.1.min.js"></script>
	<script type="text/javascript" src="/js/home/move-top.js"></script>
	<script type="text/javascript" src="/js/home/easing.js"></script>
	<script type="text/javascript" src="/js/home/address.js"></script>
</head>
<body>
  <div class="wrap">
	<div class="header">
		<div class="headertop_desc">
			<div class="call">
				<p><span>客服电话:</span><span class="number">188-1412-7570</span></p>
			</div>
			<div class="account_desc">
				<ul>
					<li><a href="#">Register</a></li>
					<li><a href="#">Login</a></li>
					<li><a href="#">Delivery</a></li>
					<li><a href="#">Checkout</a></li>
					<li><a href="#">My Account</a></li>
				</ul>
			</div>
			<div class="clear"></div>
		</div>
		<div class="header_top">
			<div class="logo">
				<a href="/home/item.action?userId=${User.userId}&item=home"><img src="/images/icon/logo.png" alt="" /></a>
			</div>
			  <div class="cart">
			  	   <%--<p>Welcome to our Online Store! <span>Cart:</span><div id="dd" class="wrapper-dropdown-2"> 0 item(s) - $0.00
			  	   	<ul class="dropdown">
							<li>you have no items in your Shopping cart</li>
					</ul></div></p>--%>
					   <a href="/home/item.action?userId=${User.userId}&item=cart"><input type="button" class="input-button" value="去购物车结算"></a>
			  </div>
			  <script type="text/javascript">
			function DropDown(el) {
				this.dd = el;
				this.initEvents();
			}
			DropDown.prototype = {
				initEvents : function() {
					var obj = this;

					obj.dd.on('click', function(event){
						$(this).toggleClass('active');
						event.stopPropagation();
					});	
				}
			}

			$(function() {

				var dd = new DropDown( $('#dd') );

				$(document).click(function() {
					// all dropdowns
					$('.wrapper-dropdown-2').removeClass('active');
				});

			});

		</script>
	 <div class="clear"></div>
  </div>
	<div class="header_bottom">
	     	<div class="menu">
	     		<ul>
					<li id="go_home"><a href="/home/item.action?userId=${User.userId}&item=home">主页</a></li>
					<li id="go_cart"><a href="/home/item.action?userId=${User.userId}&item=cart">购物车</a></li>
					<li id="go_order"><a href="/home/item.action?userId=${User.userId}&item=order">我的订单</a></li>
					<li id="go_collection"><a href="/home/item.action?userId=${User.userId}&item=collection">我的收藏</a></li>
					<li id="go_info"><a href="/home/item.action?userId=${User.userId}&item=info">个人信息</a></li>
					<li class="active" id="go_address"><a href="/home/item.action?userId=${User.userId}&item=address">收货地址</a></li>
					<li id="go_complaint"><a href="/home/item.action?userId=${User.userId}&item=complaint">投诉</a></li>
					<li id="go_suggest"><a href="/home/item.action?userId=${User.userId}&item=suggest">建议</a></li>
					<li id="go_about"><a href="/home/item.action?userId=${User.userId}&item=about">关于</a></li>
			    	<div class="clear"></div>
     			</ul>
	     	</div>
	     	<div class="search_box">
	     		<form>
	     			<input type="text" value="Search" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Search';}"><input type="submit" value="">
	     		</form>
	     	</div>
	     	<div class="clear"></div>
	     </div>	     	
   </div>
 <div class="main">
    <div class="content">
    	<div class="section group">
				  <div class="contact-form">
					  </br>
				  	<h2>我的收货地址</h2>
					  <div class="address-container">
						  </br>
						<c:forEach items="${ReceiptInfoList}" var="receipt">
							<input type='radio' value='${receipt.id}' checked='checked'> &nbsp;&nbsp;&nbsp;收货人：${receipt.name} &nbsp;&nbsp;&nbsp;联系电话：${receipt.phone} &nbsp;&nbsp;&nbsp;地址：${receipt.address} &nbsp;&nbsp;&nbsp;邮编：${receipt.zipCode}
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<input type="button" value="删除" onclick="deleteAddress(${receipt.id})" class="myButton">
							</br>
							</br>
							</br>
						</c:forEach>
						  </br>
						  <input type="button" class="myButton" value="添加地址" id="add_address">
						  </br></br></br>
					  </div>
					  <div class="add-address" style="display: none;">
						  <div>
							  <span class="name-tip"><label> 收货人 </label></span>
							  <span><input id="name" name="name" type="text" class="textbox" value="${User.name}"></span>
						  </div>
						  <div>
							  <span class="phone-tip"><label> 联系电话 </label></span>
							  <span><input id="phone" name="phone" type="text" class="textbox" value="${User.phone}"></span>
						  </div>
						  <div>
							  <span class="address-tip"><label> 收货地址 </label></span>
							  <span><input id="address" name="address" type="text" class="textbox" value=""></span>
						  </div>
						  <div>
							  <span class="code-tip"><label> 邮政编码 </label></span>
							  <span><input id="code" name="code" type="text" class="textbox" value=""></span>
						  </div>
						  <span><input type="button" class="myButton" value="添加" id="confirm">
							  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							  <input type="button" class="myButton" value="取消" id="cancel"></span>
					  </div>
				  </div>

			  </div>		
         </div> 
    </div>
 </div>
   <div class="footer">
   	  <div class="wrap">	
	     <div class="section group">
				<div class="col_1_of_4 span_1_of_4">
						<h4>Information</h4>
						<ul>
						<li><a href="about.html">About Us</a></li>
						<li><a href="contact.html">Customer Service</a></li>
						<li><a href="#">Advanced Search</a></li>
						<li><a href="delivery.html">Orders and Returns</a></li>
						<li><a href="contact.html">Contact Us</a></li>
						</ul>
					</div>
				<div class="col_1_of_4 span_1_of_4">
					<h4>Why buy from us</h4>
						<ul>
						<li><a href="about.html">About Us</a></li>
						<li><a href="contact.html">Customer Service</a></li>
						<li><a href="#">Privacy Policy</a></li>
						<li><a href="contact.html">Site Map</a></li>
						<li><a href="#">Search Terms</a></li>
						</ul>
				</div>
				<div class="col_1_of_4 span_1_of_4">
					<h4>My account</h4>
						<ul>
							<li><a href="contact.html">Sign In</a></li>
							<li><a href="index.html">View Cart</a></li>
							<li><a href="#">My Wishlist</a></li>
							<li><a href="#">Track My Order</a></li>
							<li><a href="contact.html">Help</a></li>
						</ul>
				</div>
				<div class="col_1_of_4 span_1_of_4">
					<h4>Contact</h4>
						<ul>
							<li><span>+91-123-456789</span></li>
							<li><span>+00-123-000000</span></li>
						</ul>
						<div class="social-icons">
							<h4>Follow Us</h4>
					   		  <ul>
							      <li><a href="#" target="_blank"><img src="/images/icon/facebook.png" alt="" /></a></li>
							      <li><a href="#" target="_blank"><img src="/images/icon/twitter.png" alt="" /></a></li>
							      <li><a href="#" target="_blank"><img src="/images/icon/skype.png" alt="" /> </a></li>
							      <li><a href="#" target="_blank"> <img src="/images/icon/dribbble.png" alt="" /></a></li>
							      <li><a href="#" target="_blank"> <img src="/images/icon/linkedin.png" alt="" /></a></li>
							      <div class="clear"></div>
						     </ul>
   	 					</div>
				</div>
			</div>			
        </div>
    </div>
    <script type="text/javascript">
        function deleteAddress(id) {
            $.ajax({
                url:"/module/deleteAddress.action",
                type:"post",
                dataType:"json",
                data:{
                    id:id
                },
                success:function (data) {
                    if(data.status == "delete_address_succeed"){
                        alert("删除成功");
                        window.location.href = "/home/item.action?userId=${User.userId}&item=address";
                    }else if(data.status == "delete_address_failed"){
                        alert("删除地址失败");
                    }
                },
                error:function (e) {
                    alert("发送删除地址请求错误："+e);
                }
            });
        }
		$(document).ready(function() {			
			$().UItoTop({ easingType: 'easeOutQuart' });

            $("#confirm").on("click",function () {
                var name = $("#name").val();
                var phone = $("#phone").val();
                var address = $("#address").val();
                var code = $("#code").val();
                if(name == ""){
                    $(".name-tip").text("收货人姓名不能为空！请输入");
                    $(".name-tip").css("color","#FF3030");
                }else if(phone == ""){
                    $(".phone-tip").text("联系电话不能为空！请输入");
                    $(".phone-tip").css("color","#FF3030");
                }else if(address == ""){
                    $(".address-tip").text("收货地址不能为空！请输入");
                    $(".address-tip").css("color","#FF3030");
                }else if(code == ""){
                    $(".code-tip").text("邮政编码不能为空！请输入");
                    $(".code-tip").css("color","#FF3030");
                }else{
                    $.ajax({
                        url:"/module/addAddress.action",
                        type:"post",
                        dataType:"json",
                        data:{
                            name:name,
                            phone:phone,
                            address:address,
                            code:code,
                            userId:${User.userId}
                        },
                        success:function (data) {
                            if(data.status == "add_address_succeed"){
                                alert("添加成功");
                                window.location.href = "/home/item.action?userId=${User.userId}&item=address";
                            }else if(data.status == "add_address_failed"){
                                alert("添加失败");
                            }
                        },
                        error:function (e) {
                            alert("发送添加请求失败："+e);
                        }
                    });
                }
            });
		});
	</script>
    <a href="#" id="toTop"><span id="toTopHover"> </span></a>
<%--<div style="display:none"><script src='http://v7.cnzz.com/stat.php?id=155540&web_id=155540' language='JavaScript' charset='gb2312'></script></div>--%>
</body>
</html>

